---
title: Highlighting
---

## Overview

Highlighting refers to the practice of visually emphasizing the portions of a document that match a user's
search query, which aids users in quickly identifying the relevance of the search results to
their inquiry. In ParadeDB, highlighted snippets of text are by default wrapped in `<b></b>` tags. This can
be modified with the `prefix` and `postfix` arguments.

## Basic Usage

Call `paradedb.highlight` in a `SELECT` statement, passing in the `key_field` column, the `field` to highlight,
and other highlighting options. This function only works over text fields.

If you are using two calls to `search` in the same transaction, you must pass a string `alias` argument to `search` and `highlight` to identify which results to highlight.

```sql
SELECT *, paradedb.highlight(<key_field>, field => '<field>')
FROM <index_name>.search(<query>);
```

<Accordion title="Example Usage">

```sql
SELECT *, paradedb.highlight(id, field => 'description')
FROM search_idx.search('description:keyboard OR category:electronics');

-- Multiple calls to search, alias is required.
SELECT id, paradedb.highlight(id, field => 'description')
FROM bm25_search.search('description:shoes')
UNION
SELECT id, paradedb.highlight(id, field => 'description', alias => 'speaker')
FROM bm25_search.search('description:speaker', alias => 'speaker')
ORDER BY id;
```

</Accordion>

<ParamField body="key_field" required>
  The column that represents the `key_field` of the index.
</ParamField>
<ParamField body="field" required>
  The name of the field that will be highlighted in the result.
</ParamField>
<ParamField body="prefix" default="<b>">
  The leading indicator around the highlighted region.
</ParamField>
<ParamField body="postfix" default="</b>">
  The trailing indicator around the highlighted region.
</ParamField>
<ParamField body="max_num_chars">
  Max number of characters for a highlighted fragment.
</ParamField>
<ParamField body="alias">
  A string identifier passed both to `search` and `highlight`. This is required
  only if you're using two `search` calls in one transaction, as `highlight`
  cannot otherwise know which set of highlights to use.
</ParamField>
